package day7;

import java.util.*;

public class TestTreeSet {
    public static void main(String[] args) {
        //1.数字的
        Set<String> set1 = new TreeSet(Arrays.asList(3,7,11,15,3,7));
        System.out.println(set1);
        //2.字符串
        Set<String> set2 = new TreeSet(Arrays.asList("邓志涛","何鑫宇","陈毓坚"));
        Set<String> set22 = new TreeSet<>((s1,s2) -> s2.compareTo(s1));
        set22.addAll(set2);
        System.out.println(set2);
        System.out.println(set22);
        //3.对象类排序：斗地主针对牌对象排序
        //♥10 ♠J ♣3 ♦10 🃏
        //🃏  ♠J ♥10 ♦10 ♣3
        Set<Card> set3 = new TreeSet<>();
        //定义所有的牌对象 定义存储所有的牌对象
        String[] color = {"♣","♠","♥","♦"};
        String[] number = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        List<Card> cards = new ArrayList<>();
        for (String s:color) {
            for (int i = 0; i < number.length; i++) {
                cards.add(new Card(s+number[i],i+3));
            }
        }
        cards.add(new Card("小🃏",16));
        cards.add(new Card("大🃏",17));
        System.out.println(cards);
        //打乱顺序
        Collections.shuffle(cards);
        Random r = new Random();
        Set<Card> set4 = new TreeSet<>((c1,c2)->{
            int i = c2.num-c1.num;
            if (i==0) i = c1.str.compareTo(c2.str);
            return i;
        });
        for (int i = 0; i < 10; i++) {
           int index = r.nextInt(cards.size());
           set4.add(cards.get(index));
        }
        System.out.println(set4);
    }
}

class Card{
    String str;//存储内容 ♣10
    int num;//存储牌对应的数值

    public Card(String str, int num) {
        this.str = str;
        this.num = num;
    }
    public String toString() {
        return str;
    }
}